package com.focus.xyz.other.pages.tpytb.baby;

import com.focus.xyz.core.common.keyword.Action;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/5/16.
 */
public class HomePage{
    private Action action;
    private WebDriver driver;


    @FindBy(id = "bxsw")
    private WebElement bxsw;
    @FindBy(id = "bxsw_fntb")
    private WebElement fatb;
    @FindBy(id = "sd2")
    private WebElement bx2;
    @FindBy(id = "sd3")
    private WebElement bx1;
    @FindBy(xpath = "//a[text()='学生幼儿意外伤害综合保险（13版）']")
    private WebElement adir;

    private List<WebElement> frames;

    public HomePage(WebDriver driver,Action action){
        this.driver = driver;
        this.action = action;
        PageFactory.initElements(driver,this);
    }

    public void clickDir() throws Exception{
        action.click(adir);
    }

    public void clickBx1() throws Exception{
        action.click(bx1);
    }

    public void clickBx2() throws Exception{
        action.click(bx2);
    }

    public void clickfntb() throws Exception{
        action.click(bxsw);
        action.click(fatb);
    }

    public void switchTop() throws Exception{
//        driver.switchTo().defaultContent();
        driver.switchTo().frame("topFrame");
    }

    public void switchLeft() throws Exception{
        driver.switchTo().defaultContent();
        driver.switchTo().frame("rightFrame");
        WebElement frameset = driver.findElement(By.tagName("frameset"));
        frames = frameset.findElements(By.tagName("frame"));
        driver.switchTo().frame(frames.get(0));

    }



    public void switchRight() throws Exception{
        driver.switchTo().defaultContent();
        driver.switchTo().frame("rightFrame");
        WebElement frameset = driver.findElement(By.tagName("frameset"));
        frames = frameset.findElements(By.tagName("frame"));
        driver.switchTo().frame(frames.get(1));
    }

    public void switchToParent() throws Exception{
        driver.switchTo().parentFrame();
    }



}
